import node_fetch from 'node-fetch'
import { IUserInfo } from '../interface'

export default function login(nodejs: string, user: string, password: string): Promise<IUserInfo> {
	return new Promise((resolve) => {
		node_fetch(nodejs + '/test-login', {
			method: 'POST',
			headers: {
				'Connection': 'Keep-Alive',
				'Content-Type': 'application/json'
			},
			body: JSON.stringify({
				user,
				password
			})
		}).then((res) => {
			return res.json()
		}).then((json) => {
			resolve(json)
		})
	})
}
